%  This file is part of Erlywog.

%  Erlywog is free software: you can redistribute it and/or modify
%  it under the terms of the GNU General Public License as published by
%  the Free Software Foundation, either version 3 of the License, or
%  (at your option) any later version.

%  Erlywog is distributed in the hope that it will be useful,
%  but WITHOUT ANY WARRANTY; without even the implied warranty of
%  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%  GNU General Public License for more details.

%  You should have received a copy of the GNU General Public License
%  along with Erlywog.  If not, see <http://www.gnu.org/licenses/>.

%  Copyright Jasm Sison 2009

-module(test_controller).
-export([
 	index/1
 	, yaws_params/1
 	, test1/1
	, test2/1
	, test3/1
%	, test4/1
% 	, test5/1
% 	, test_response1/1
	, test_internal_redirect/1
	, test_xhr_ajax_response/1
 	, test_response2/1
	]).

index(A) ->
  [
    {ewc, test, yaws_params, [A]}
    , {data,<<"Waaaaheeeeeeeeeeeeeeeeeeeeeeeeeeeeeey!">>}
  ].
  
yaws_params (A) ->
  Y = yaws_arg
  , E = erlyweb
  , {data,
        { 
            _approot = E:get_app_root(A)
          , _docroot = Y:docroot(A)
          , _fullpath = Y:fullpath(A)
          , _appmoddata = Y:appmoddata(A)
          , _serverpath = Y:server_path(A)
        }
      }.
      
%% test

test1(A) ->
  {data, "test1"}.
  
test2(A) ->
  {data, "test2"}.
  
test3(A) ->
%   {data, "md5.js"}.
  {response, [{redirect_local, "/js/md5.js"}]}.
  
%% useful for internal redirects  
test_internal_redirect(A_) ->
  {response, {page, "/js/md5.js"}}.

%% useful for xhr/ajax responses
test_xhr_ajax_response(A) ->
  {response, [{html, "No (html) shit huh?!"}]}. %% works great!
  
test_response2(A) ->
%   {response, [{body, [{ewc, test, test1, [A]},{ewc, test, test2, [A]}]}]}. %% works!
%   {response, [{body, {ewc, test, test1, [A]}}]}. %% works!
  {response, {body, {ewc, test, test1, [A]}}}. %% works!
  %% I don't exactly understand the point of this yaws tuple ...
  %% I guess you can do component nesting this way
  %% Instead of [ Ewc, Ewc, Ewc etc... ]

  
  
